home *** CD-ROM | disk | FTP | other *** search
/ Introduction to 3D Game …ogramming with DirectX 12 / Introduction-to-3D-Game-Programming-with-DirectX-12.ISO / Code.Textures / Chapter 20 Shadow Mapping / Shadows / FrameResource.h < prev    next >
Encoding:
C/C++ Source or Header  |  2016-03-02  |  3.1 KB  |  92 lines

  1. #pragma once
  2.  
  3. #include "../../Common/d3dUtil.h"
  4. #include "../../Common/MathHelper.h"
  5. #include "../../Common/UploadBuffer.h"
  6.  
  7. struct ObjectConstants
  8. {
  9.     DirectX::XMFLOAT4X4 World = MathHelper::Identity4x4();
  10.     DirectX::XMFLOAT4X4 TexTransform = MathHelper::Identity4x4();
  11.     UINT     MaterialIndex;
  12.     UINT     ObjPad0;
  13.     UINT     ObjPad1;
  14.     UINT     ObjPad2;
  15. };
  16.  
  17. struct PassConstants
  18. {
  19.     DirectX::XMFLOAT4X4 View = MathHelper::Identity4x4();
  20.     DirectX::XMFLOAT4X4 InvView = MathHelper::Identity4x4();
  21.     DirectX::XMFLOAT4X4 Proj = MathHelper::Identity4x4();
  22.     DirectX::XMFLOAT4X4 InvProj = MathHelper::Identity4x4();
  23.     DirectX::XMFLOAT4X4 ViewProj = MathHelper::Identity4x4();
  24.     DirectX::XMFLOAT4X4 InvViewProj = MathHelper::Identity4x4();
  25.     DirectX::XMFLOAT4X4 ShadowTransform = MathHelper::Identity4x4();
  26.     DirectX::XMFLOAT3 EyePosW = { 0.0f, 0.0f, 0.0f };
  27.     float cbPerObjectPad1 = 0.0f;
  28.     DirectX::XMFLOAT2 RenderTargetSize = { 0.0f, 0.0f };
  29.     DirectX::XMFLOAT2 InvRenderTargetSize = { 0.0f, 0.0f };
  30.     float NearZ = 0.0f;
  31.     float FarZ = 0.0f;
  32.     float TotalTime = 0.0f;
  33.     float DeltaTime = 0.0f;
  34.  
  35.     DirectX::XMFLOAT4 AmbientLight = { 0.0f, 0.0f, 0.0f, 1.0f };
  36.  
  37.     // Indices [0, NUM_DIR_LIGHTS) are directional lights;
  38.     // indices [NUM_DIR_LIGHTS, NUM_DIR_LIGHTS+NUM_POINT_LIGHTS) are point lights;
  39.     // indices [NUM_DIR_LIGHTS+NUM_POINT_LIGHTS, NUM_DIR_LIGHTS+NUM_POINT_LIGHT+NUM_SPOT_LIGHTS)
  40.     // are spot lights for a maximum of MaxLights per object.
  41.     Light Lights[MaxLights];
  42. };
  43.  
  44. struct MaterialData
  45. {
  46.     DirectX::XMFLOAT4 DiffuseAlbedo = { 1.0f, 1.0f, 1.0f, 1.0f };
  47.     DirectX::XMFLOAT3 FresnelR0 = { 0.01f, 0.01f, 0.01f };
  48.     float Roughness = 0.5f;
  49.  
  50.     // Used in texture mapping.
  51.     DirectX::XMFLOAT4X4 MatTransform = MathHelper::Identity4x4();
  52.  
  53.     UINT DiffuseMapIndex = 0;
  54.     UINT NormalMapIndex = 0;
  55.     UINT MaterialPad1;
  56.     UINT MaterialPad2;
  57. };
  58.  
  59. struct Vertex
  60. {
  61.     DirectX::XMFLOAT3 Pos;
  62.     DirectX::XMFLOAT3 Normal;
  63.     DirectX::XMFLOAT2 TexC;
  64.     DirectX::XMFLOAT3 TangentU;
  65. };
  66.  
  67. // Stores the resources needed for the CPU to build the command lists
  68. // for a frame.  
  69. struct FrameResource
  70. {
  71. public:
  72.     
  73.     FrameResource(ID3D12Device* device, UINT passCount, UINT objectCount, UINT materialCount);
  74.     FrameResource(const FrameResource& rhs) = delete;
  75.     FrameResource& operator=(const FrameResource& rhs) = delete;
  76.     ~FrameResource();
  77.  
  78.     // We cannot reset the allocator until the GPU is done processing the commands.
  79.     // So each frame needs their own allocator.
  80.     Microsoft::WRL::ComPtr<ID3D12CommandAllocator> CmdListAlloc;
  81.  
  82.     // We cannot update a cbuffer until the GPU is done processing the commands
  83.     // that reference it.  So each frame needs their own cbuffers.
  84.     std::unique_ptr<UploadBuffer<PassConstants>> PassCB = nullptr;
  85.     std::unique_ptr<UploadBuffer<ObjectConstants>> ObjectCB = nullptr;
  86.  
  87.     std::unique_ptr<UploadBuffer<MaterialData>> MaterialBuffer = nullptr;
  88.  
  89.     // Fence value to mark commands up to this fence point.  This lets us
  90.     // check if these frame resources are still in use by the GPU.
  91.     UINT64 Fence = 0;
  92. };